#enconding =utf-8
from django.http import HttpResponse
from django.shortcuts import render

from stu.models import Student


def hello_world(request):
    return render(request, "login/index.html")

def login(request):
    name=request.POST.get('uname')
    pwd=request.POST.get('pwd')
    if name=='azheng' and pwd =='151365':
        return  HttpResponse("登录成功")
    else:
        return HttpResponse("登录失败")

def login_mysql(request):
    name=request.POST.get('uname')
    pwd=request.POST.get('pwd')
    student=Student()
   # " select * from student where name=name and pwd =pwd"%name,pwd
    students = Student.objects.filter(name=name, pwd=pwd)

    if students.exists():
        return  HttpResponse("登录成功")
    else:
        return HttpResponse("登录失败")
def register(request) :
    name = request.POST.get('uname')
    pwd = request.POST.get('pwd')
    if Student.objects.filter(name=name, pwd=pwd).exists():
        return HttpResponse("用户名已存在")
    else:
        student = Student(name=name, pwd=pwd)
        student.save()
        return HttpResponse("注册成功")
